package cc.admin.modules.sys.service.impl;

import cc.admin.common.db.table.base.EtlReader;
import cc.admin.common.db.table.entity.DbEntity;
import cc.admin.common.util.security.SecurityTools;
import cc.admin.modules.sys.entity.SysDataSource;
import cc.admin.modules.sys.mapper.SysDataSourceMapper;
import cc.admin.modules.sys.service.ISysDataSourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 多数据源管理
 * @Author: jeecg-boot
 * @Date: 2019-12-25
 * @Version: V1.0
 */
@Service
public class SysDataSourceServiceImpl extends ServiceImpl<SysDataSourceMapper, SysDataSource> implements ISysDataSourceService {

	@Autowired
	SysDataSourceMapper sysDataSourceMapper;

	@Override
	public List<DbEntity> tables(String id) {
		EtlReader etlReader = EtlReader.getInstance(id).init();
		return etlReader.readEntity();
	}

	@Override
	public void insert(SysDataSource sysDataSource) {
		String encodePwd = SecurityTools.aseEncode(sysDataSource.getDbPassword());
		sysDataSource.setDbPassword(encodePwd);
		sysDataSourceMapper.insert(sysDataSource);
	}
}
